package javaweek11;

import java.util.Scanner;

class Repo{
	String[] string;
	public static boolean gender1 = true;
	public static boolean gender2 = true;
	public Repo(String items) {
		string = items.split(" ");
	}
	int getSize(){
		int size = 0;
		for (int i = 0; i < string.length; i++) {
			if (string[i]!= null) size ++;
		}
		return size;
	}
	synchronized String deleteTask(){
		String str = string[0];
		for (int i = 0; i < string.length-1; i++) {
			string[i] = string[i+1];
		}
		this.string[string.length - 1] = null;
		return str;
	}
}
class Worker1 implements Runnable{
	private Repo repo;
	public Worker1(Repo repo) {
		// TODO Auto-generated constructor stub
		this.repo = repo;
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		while (repo.getSize()!=0) {
			if (Repo.gender1 == true){
				System.out.println(Thread.currentThread().getName()+" finish "+repo.deleteTask());
				Repo.gender1 = false; 
				Repo.gender2 = true;
			}
		}
		
	}	
}
class Worker2 implements Runnable{

	private Repo repo;
	public Worker2(Repo repo) {
		// TODO Auto-generated constructor stub
		this.repo = repo;
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		while (repo.getSize()!=0) {
			if (Repo.gender2 == true){
				System.out.println(Thread.currentThread().getName()+" finish "+repo.deleteTask());
				Repo.gender2 = false; 
				Repo.gender1 = true;
			}
		}		
	}
}
public class function06 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
        Repo repo = new Repo(sc.nextLine());
        Thread t1 = new Thread(new Worker1(repo));
        Thread t2 = new Thread(new Worker2(repo));
        t1.start();
        Thread.yield();
        t2.start();
        sc.close();
	}

}
